<template>
  <div>
    <elm-page-tb>
      <template #top>
        <el-input placeholder="进货批次" size="mini" prefix-icon='el-icon-search' style="width: 250px;margin: 0 10px" v-model="postData.name" clearable></el-input>
        <elm-select placeholder="货物名称" size="mini" v-model="postData.dict" style="width: 250px;margin: 0 10px" url="/business/jxc/goods/dict/GetData" clearable></elm-select>
        <right>
          <el-button-group>
            <el-button icon="el-icon-search" size="mini" @click="tablebinding()">查询</el-button>
            <elm-open-button url="goods_edit" title="新增" width="900" height="50%">新增</elm-open-button>
          </el-button-group>
        </right>
      </template>
      <elm-table url="/business/jxc/goods/GetData" :post-data="postData" :page-size="10" height="100%">
        <el-table-column prop="name" label="进货批次" align="center" header-align="center"></el-table-column>
        <el-table-column prop="dict_mc" label="货物名称" align="center" header-align="center"></el-table-column>
        <el-table-column prop="specification" label="规格/型号" align="center" header-align="center" width="90"></el-table-column>
        <el-table-column prop="unit" label="单位" align="center" header-align="center"></el-table-column>
        <el-table-column prop="quantity" label="数量" align="right" header-align="center"></el-table-column>
        <el-table-column prop="price" label="进货价格" align="right" header-align="center"></el-table-column>
        <el-table-column prop="tex" label="税率" align="center" header-align="center">
          <template v-slot="scope">
            {{scope.row.tex?scope.row.tex+"%":""}}
          </template>
        </el-table-column>
        <el-table-column prop="manufacturer" label="厂家" align="left" header-align="center"></el-table-column>
        <el-table-column prop="made_date" label="生产日期" align="center" width="100" :formatter="formatDate"></el-table-column>
        <el-table-column prop="shelf_life" label="保质期至" align="center" width="100" :formatter="formatDate"></el-table-column>
        <el-table-column prop="remarks" label="备注" align="center" header-align="center"></el-table-column>
        <el-table-column prop="last_update_time" label="最后更新时间" align="center" width="160" :formatter="formatDateTime"></el-table-column>
        <el-table-column fixed="right" label="操作" width="100px" align="center">
          <template v-slot="scope">
            <elm-open-button url="goods_edit" title="调整"  width="900" height="50%" :data="{ model: scope.row }" type="text">调整</elm-open-button>
            <el-button  type="text" size="mini" @click="deleteData(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </elm-table>
    </elm-page-tb>
  </div>

</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      postData: { name: null}
    }
  },
  created() {
  },
  methods: {
    async deleteData(data) {
      await this.delete('/business/jxc/goods/Delete', { id: data.id });
      let res=await elm.post("/business/jxc/goods/dict/GetData",{id:data.dict});
      if(res.pagedata.length>0){
        let upData=res.pagedata[0];
        upData.quantity-=Number(data.quantity);
        await elm.post('/business/jxc/goods/dict/Upsert', upData);
      }
      this.tablebinding();
    },
  }
}
</script>
